<?php
namespace Home\Controller;
class TestController extends CommonController {
public function _initialize()
{
	set_time_limit(0);
	ini_set('max_execution_time', '0');
	ini_set('memory_limit','500M');
	ob_end_clean();
}
public function requirement()
{
	// $order = M('order')->where("id < 97274 and (requirement=2 or requirement=3)")->field('id,requirement')->order("id desc")->select();
	// $theorder = M('theorder')->where("(state=3 or state=4) and (demand=2 or demand=3)")->field('id,demand')->order("id desc")->select();
	// p($theorder);exit();
	foreach ($order as &$vo) {
		foreach ($theorder as $key => $val) {
			if ($vo['id'] == $val['id']) {
				$ids = $vo['id'];
				switch ($val['demand']) {
					case '2':
						M('order')->where("id = $ids")->save(array('requirement'=>3));
						break;
					case '3':
						M('order')->where("id = $ids")->save(array('requirement'=>2));
						break;
				}
			}
		}
	}
}

	// 数据
	public function sendmember()
	{
		$sex = 1;
		$type = 1;
		$db_sendmember = M('sendmember s');
		$where['sendswitch'] = 1;
		$where['getorder'] = 0;
		if ($sex != 0) {
			$where['sex'] = $sex;
		}
		$where['soundtype'] = array("like","%".($type-1)."%");
		$where['s.status']=1;
		$where['m.status']=9;
		$senduser = $db_sendmember->join('__MEMBER__ m ON s.uuid = m.uuid',LEFT)->field('s.uuid')->where($where)->order('getsendnum+0 asc,sendswitchtime asc')->find()['uuid'];
		echo $senduser;
	}
public function aaa()
{
  // $data2 = M('theorder')->where(" (state = 2) and (attribute = 3) and id > 94941")->select();
// p($data2);exit();
  foreach ($data2 as &$vo) {
      $media = M('media')->where(array('id'=>$vo['mid']))->find();
      $data['id'] = $vo['id'];
      $data['media_id'] = $vo['mid'];
      $data['media_name'] = $media['media_name'];
      $data['media_tel'] = $media['media_tel'];
      $data['media_pic'] = $media['media_pic'];
      $data['media_message'] = $media['media_message'];
      $data['article_id'] = $vo['articleid'];
      $data['bgm_id'] = 0;
      $data['user_id'] = $vo['uuid'];
      $data['type'] = $vo['attribute']  + 1;
      $data['sub_type']  = 0;
      $data['requirement'] = 1;
      $data['title'] = $vo['title'];
      $data['content'] = $vo['content'];
      $data['words'] = $vo['words'];
      $data['category'] = $vo['type'] + 1;
      $data['speed'] = $vo['speed'] + 1;
      $data['sex'] = $vo['sex'];
      $data['level'] = $vo['level'];
      $data['is_read_title'] = $vo['readtitle'];
      $data['note'] = '原始数据 无备注';
      $data['price'] = $vo['money'];
      $data['increase_price'] = $vo['premium'];
      $data['max_join_num'] = $vo['largestnumber'];
      $data['actual_join_num'] = $vo['actualnumber'];
      $data['deliver_time'] = $vo['expectedtime'];
      $data['score'] = $vo['score'];
      $weincome = M('wemediaincome')->where(array('oid'=>$vo['id']))->find();
      $data['pay_type'] = 5;
      $data['pay_status'] = 1;
      $data['pay_time'] = $vo['releasetime'];
      $data['status']  = 3;
      $data['createtime'] = $vo['createtime'];
      $data['add_time'] = date('YmdH', $vo['releasetime']);
      $data['snatch_time'] = '60';
      $data['delay_type'] = 3;
      $data['email'] = $vo['email'];
      $data['isremind'] = 1;
      $data['audio_link'] = $vo['linkaudio'];
      $data['audio_upload_time'] = $vo['linkaudiotime'];
      $data['adminid'] = 29;
      $data['isautochose'] = $vo['isautochose'];
      $data['operating_time'] = $vo['operatingtime'];
      // M('order')->add($data);
  }
}

function deleteredis(){
	// $oid = 1113658;
	// $userlist = M("member")->where(array("state"=>9))->field("uuid")->select();
	foreach ($userlist as $key => $value) {
		$uuid_array = "";
		$uuid_array = json_decode(RedisGet("uuid".$value['uuid']),TRUE);
		foreach ($uuid_array['order_list'] as $key => &$vo) {
			if ($vo['oid'] == $oid) {
				// p($vo);echo $key;
				if ($vo['state']==1) {
					$vo['state']=11;
					// unset($uuid_array['order_list'][$key]);
				}
			}
		}
		RedisSet('uuid'.$value['uuid'],json_encode($uuid_array));
	}
}
function updatemember(){
	// $data = M("data")->select();
	foreach ($data as $key => $value) {
		if ($value['bgm_audio_type']==1) {
			M("member")->where(array("uuid"=>$value['uuid']))->save(array("is_bgm"=>2));
		}
		if ($value['introduction_audio_type']==1) {
			M("member")->where(array("uuid"=>$value['uuid']))->save(array("is_introduction"=>2));
		}
		if ($value['short_audio_type']==1) {
			M("member")->where(array("uuid"=>$value['uuid']))->save(array("is_distribute"=>2));
		}
	}
}
function updateredis(){
	// $order = M("order")->where("(status=5 or status=7 or status=3 or status=9) and (type=1 or type=2) and user_id=100006")->select();
	// p($order);exit();
	foreach ($order as $key => $value) {
		$uuid_array = array();
		$order_array = array();
		if ($value['user_id']) {

			$uuid_array = json_decode(RedisGet("uuid".$value['user_id']),TRUE);
			if (empty($uuid_array['unread']['1'])) {
				$uuid_array['unread']['1'] = 0;
			}
			if (empty($uuid_array['unread']['2'])) {
				$uuid_array['unread']['2'] = 0;
			}
			$arr['oid'] = $value['id'];
			$arr['shot_time'] = 1;
			$arr['state'] = 5;
			$arr['type'] = $value['type'];
			$uuid_array['order_list'][] = $arr;
			// p($uuid_array);
			RedisSet('uuid'.$value['user_id'],json_encode($uuid_array));
			$order_array['list'][$value['user_id']] = 1;
			$order_array['status'] = 1;
			// p($order_array);
			// RedisSet('order'.$value['id'],json_encode($order_array));
		}
	}
}
	public function sendordernum()
	{
		header("Content-type:application/vnd.ms-excel");
		header("Content-Disposition:filename=派单主播数据.xls");
		$today = strtotime(date("Y-m-d",time()));
		// $frist = "1520956800";//3-14
		$frist = strtotime("2018-06-12");//7-10
// echo $frist;exit();
		while ($today>$frist) {
			$data[] = array("strat"=>($today-86400),"end"=>$today);
			$today -= 86400;
		}
		$strexport.="日期\t单量\r";
		foreach ($data as $key => $value) {
			$strat = $value['strat'];
			$end = $value['end'];
			$where['releasetime'] = array("BETWEEN",array($strat,$end));
			$strexport.=date('Y-m-d',$strat)."\t";
			$sendnum = M('theorder')
			// ->field('user_id,count(user_id) count')
			->where("(issend=1) AND (state=3 or state=4)")
			->where($where)
			// ->order("count(user_id) desc")
			// ->group('user_id')
			->count();
			// $date = date("Ymd",$strat);
			// foreach ($sendorder as &$vo) {
				// $vo['num'] = M("sendverify")->where(array("date"=>$date,"uuid"=>$vo['user_id']))->order("num desc")->find()['num'];
				$strexport.=$sendnum."\r";
			// }
		}
		$strexport=iconv('UTF-8',"GB2312//IGNORE",$strexport);
			// $this->adminlog("导出派单主播数据");
		exit($strexport);
	}

function user_pool(){
	$db_memberpool = M("memberpool");
	$all_user = M("member")->where(array("status"=>9,"uuid"=>array("NEQ","100001")))->select();
	$leveldata = M("systemsetup")->where(array("type"=>1))->order('value asc')->select();
	foreach ($all_user as $key => $user) {
		if ($db_memberpool->where(array("uuid"=>$user['uuid']))->find()) {
			$db_memberpool->where(array("uuid"=>$user['uuid']))->delete();
		}
		$sex = $user['sex'];
		$score = $user['score']>52?1:0;
		foreach ($leveldata as $k => $v) {
			if($user['level'] >= $v['value']){$grade = $v['id'];}
		}
		// 讲述
		if (strpos($user['soundtype'], "0") !== false) {
			$soundtype = 1;
			$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype."0".$grade."0"));
			$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype.$sex.$grade."0"));
			if ($score == 1) {
				$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype."0".$grade.$score));
				$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype.$sex.$grade.$score));
			}
		}
		// 情感
		if (strpos($user['soundtype'], "1") !== false) {
			$soundtype = 2;
			$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype."0".$grade."0"));
			$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype.$sex.$grade."0"));
			if ($score == 1) {
				$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype."0".$grade.$score));
				$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype.$sex.$grade.$score));
			}
		}
		// 演绎
		if (strpos($user['soundtype'], "2") !== false) {
			$soundtype = 3;
			$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype."0".$grade."0"));
			$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype.$sex.$grade."0"));
			if ($score == 1) {
				$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype."0".$grade.$score));
				$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype.$sex.$grade.$score));
			}
		}
		// 新闻
		if (strpos($user['soundtype'], "3") !== false) {
			$soundtype = 4;
			$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype."0".$grade."0"));
			$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype.$sex.$grade."0"));
			if ($score == 1) {
				$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype."0".$grade.$score));
				$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype.$sex.$grade.$score));
			}
		}
		// 英文
		if (strpos($user['soundtype'], "4") !== false) {
			$soundtype = 5;
			$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype."0".$grade."0"));
			$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype.$sex.$grade."0"));
			if ($score == 1) {
				$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype."0".$grade.$score));
				$db_memberpool->add(array("uuid"=>$user['uuid'],"label"=>$soundtype.$sex.$grade.$score));
			}
		}
	}
}
/*##########################################################*/
}


